package com.googlecode.sc2dm.annotations.types;

import android.content.Context;
import android.content.Intent;

import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;

/**
 * @Author Jarle Hansen (jarle@jarlehansen.net)
 * Created: 7:47 PM - 9/19/11
 */
public class OnMessageObject extends AnnotatedObject {
    public OnMessageObject(Class<?> clazz, Method method) {
        super(clazz, method);
    }

    public void invokeOnMessage(Context context, Intent intent) {
        Object instance = super.instance();

        try {
            if (intent.hasExtra("msg")) {
                method.invoke(instance, buildArgs(context, intent.getStringExtra("msg")));
            }
        } catch (InvocationTargetException e) {
            e.printStackTrace();
        } catch (IllegalAccessException e) {
            e.printStackTrace();
        }
    }
}
